package main

import (
	"fmt"
	"sync"
	"time"
)

func fn1(ch chan<- int) {
	for i := 1; i <= 10; i++ {
		ch <- i
		fmt.Printf("【写入】数据%v成功\n", i)
		time.Sleep(time.Millisecond * 50)
	}
	close(ch)
	wg.Done()
}

func fn2(ch <-chan int) {
	for val := range ch {
		// <-ch
		fmt.Printf("【读取】数据%v成功\n", val)
		time.Sleep(time.Millisecond * 50)
	}
	wg.Done()
}

var wg sync.WaitGroup

func main() {
	var ch = make(chan int, 10)

	wg.Add(1)
	go fn1(ch)

	wg.Add(1)
	go fn2(ch)

	wg.Wait()
}
